package com.ctgu.j08.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.j08.common.enums.ResultEnum;
import com.ctgu.j08.mapper.DeviceMapper;
import com.ctgu.j08.mapper.RepairMapper;
import com.ctgu.j08.mapper.TroubleMapper;
import com.ctgu.j08.service.TroubleService;
import com.ctgu.j08.utils.ResultUtil;
import com.ctgu.j08.vo.DUser;
import com.ctgu.j08.vo.Repair;
import com.ctgu.j08.vo.Result;
import com.ctgu.j08.vo.Trouble;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.0
 * @author: Saiya Wang
 * @date: 2021/6/3 9:57
 */
@Service
public class TroubleServiceImpl extends ServiceImpl<TroubleMapper, Trouble> implements TroubleService {
    @Autowired
    private TroubleMapper troubleMapper;
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private RepairMapper repairMapper;
    @Override
    public Result editTrouble(Trouble trouble) {
//        int deId = trouble.getDeId();
//        int deStatus = 2;
        int trStatus = 1;
        int trId = trouble.getTrId();
        //更新自己的状态
        int isUp = troubleMapper.updateStatus(trId,trStatus);
//        //更新设备状态
//        int isUpDevice = deviceMapper.updateStatus(deId,deStatus);
        //维修表插入信息

        if(isUp != 0)
        {
            return ResultUtil.success(ResultEnum.SUCCESS);
        }
        else
        {
            System.out.println("更新失败"+isUp);
            return ResultUtil.error(ResultEnum.FAIL);
        }
    }

    @Override
    public Result addTrouble(Trouble trouble) {
        int isAdd = troubleMapper.insertSelective(trouble);
        if(isAdd != 0)
        {
            return ResultUtil.success(ResultEnum.SUCCESS);
        }
        else
        {
            System.out.println("报修失败"+isAdd);
            return ResultUtil.error(ResultEnum.FAIL);
        }
    }

    @Override
    public Result getAllTroubleInfo() {
        List<Trouble> troubleList = troubleMapper.getAllTroubleInfo();
        if(troubleList == null)
        {
            return ResultUtil.error(ResultEnum.FAIL);
        }else
        {
            System.out.println("报修信息列表："+troubleList);
            return ResultUtil.success(troubleList);
        }
    }
}
